package org.springblade.modules.admin.task;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springblade.modules.admin.enums.MaintainPlanContentEnum;
import org.springblade.modules.admin.service.IMaintainSignService;
import org.springblade.modules.admin.service.MaintainPlanUserDayCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


/**
 * @Date 15:07 2022/7/26
 * @Description {
 * 工单每天每人统计 及每日凌晨系统签退
 * }
 * @Author lsay
 **/
@Component
public class PlanUserDayCountJob {

	@Autowired
	private MaintainPlanUserDayCountService planUserDayCountService;
	@Autowired
	private IMaintainSignService signService;

	/**
	 * 每天 23:30 所有保养工单未签退人员系统代签
	 */
	//@Scheduled(cron = "0 30 23 * * ?")
	@XxlJob(value = "systemSign")
	public void systemSign() {
		XxlJobHelper.handleSuccess("保养工单未签退人员系统代签-(systemSign)-[执行]开始");
		try {
			signService.systemSignByNotSignOut(MaintainPlanContentEnum.MAINTAIN_BY.getId());
			XxlJobHelper.handleSuccess("保养工单未签退人员系统代签-(systemSign)-[执行]成功");
		} catch (Exception e) {
			XxlJobHelper.handleSuccess("保养工单未签退人员系统代签-(systemSign)-[执行]失败" + e);
		}

	}

	/**
	 * 每天 01:00 统计所有工单
	 */
	//@Scheduled(cron = "0 0 1 * * ?")
	@XxlJob(value = "planUserDayCount")
	public void planUserDayCount() {
		XxlJobHelper.handleSuccess("统计所有工单-(planUserDayCount)-[执行]开始");

		try {
			planUserDayCountService.updatePlanUserDayCount(MaintainPlanContentEnum.MAINTAIN_BY.getId());
			// 维修和配件工单
			planUserDayCountService.updateWxPlanUserDayCount(String.format("%s,%s", MaintainPlanContentEnum.MAINTAIN_WX.getId(), MaintainPlanContentEnum.MAINTAIN_PARTS.getId()));
			XxlJobHelper.handleSuccess("统计所有工单-(planUserDayCount)-[执行]成功");
		} catch (Exception e) {
			XxlJobHelper.handleSuccess("统计所有工单-(planUserDayCount)-[执行]失败" + e);
		}
	}

}
